package com.achievo.know.web.util;

import java.io.IOException;
import java.io.InputStreamReader;

public class Pdf2SwfUtil {
	// java调用cmd命令行方法

	/**
	 * 
	 * 运行可执行文件
	 * 
	 * 
	 * 
	 * @param cmd
	 * 
	 * @return String
	 */

	public static synchronized boolean executeCmdFlash(String cmd) {
		StringBuilder stdout = new StringBuilder();

		try {

			final Process process = Runtime.getRuntime().exec(cmd);

			Runtime.getRuntime().addShutdownHook(new Thread() {

				public void run() {

					process.destroy();

				}

			});

			InputStreamReader inputstreamreader = new InputStreamReader(process
					.getInputStream());

			char c = (char) inputstreamreader.read();

			if (c != '\uFFFF')

				stdout.append(c);

			while (c != '\uFFFF') {

				if (!inputstreamreader.ready()) {

					System.out.println(stdout);

					try {

						process.exitValue();

						break;

					}

					catch (IllegalThreadStateException _ex) {

						try {

							Thread.sleep(100L);

						}

						catch (InterruptedException _ex2) {

						}

					}

				} else {

					c = (char) inputstreamreader.read();

					stdout.append(c);

				}

			}

			try {

				inputstreamreader.close();

			}

			catch (IOException ioexception2) {

				System.err.println("RunCmd : Error closing InputStream "
						+ ioexception2);

				return false;

			}

		} catch (Throwable e) {

			e.printStackTrace();

			return false;

		}

		return true;

	}
}
